/*
 * @Author: szx
 * @Date: 2022-03-19 13:26:32
 * @LastEditTime: 2022-03-19 13:27:49
 * @Description:
 * @FilePath: \leetcode\剑指offer\18\18.js
 */
/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} val
 * @return {ListNode}
 */
var deleteNode = function (head, val) {
    const prev = new ListNode(-1);
    prev.next = head;
    let node = prev;
    while (node.next) {
        if (node.next.val === val) {
            node.next = node.next.next;
            break;
        }
        node = node.next;
    }
    return prev.next;
};
